package com.liang.demo.controller;

import com.liang.demo.base.RestResponse;
import com.liang.demo.po.Admin;
import com.liang.demo.po.Menu;
import com.liang.demo.po.Resource;
import com.liang.demo.po.Role;
import com.liang.demo.service.AdminService;
import com.liang.demo.service.MenuService;
import com.liang.demo.service.ResourceService;
import com.liang.demo.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 陈琪亮
 * @version 1.0
 * @date 2021/3/21 15:04
 */
@RestController
public class AuthController {

    @Autowired
    private AdminService adminService;

    @Autowired
    private RoleService roleService;

    @Autowired
    private MenuService menuService;

    @Autowired
    private ResourceService resourceService;


    //获取用户列表
    @PreAuthorize("hasAuthority('authUserList:*')")
    @GetMapping("/api/auth/admin/list")
    public RestResponse<List<Admin>> getAdminList() {
        List<Admin> adminList = adminService.getAdminAll();
        return RestResponse.ok(adminList);
    }

    @GetMapping("/api/auth/role/list")
    public RestResponse<List<Role>> getRoleAll() {
        List<Role> list = roleService.getRoleAll();
        return RestResponse.ok(list);
    }

    @GetMapping("/api/auth/menu/list")
    public RestResponse<List<Menu>> getMenuAll() {
        List<Menu> menuList = menuService.getMenuAll();
        return RestResponse.ok(menuList);
    }

    @GetMapping("/api/auth/resource/list")
    public RestResponse<List<Resource>> getResourceAll() {
        List<Resource> resourceList = resourceService.getResourceAll();
        return RestResponse.ok(resourceList);
    }
}
